package com.kedacom.ctsp.authz.oauth2.client.service;

import com.kedacom.ctsp.authority.vo.DepartmentVO;
import com.kedacom.ctsp.authority.vo.ResourceVO;
import com.kedacom.ctsp.authz.entity.AuthResource;
import com.kedacom.ctsp.authz.oauth2.core.OAuth2Authentication;
import com.kedacom.ctsp.authz.oauth2.core.vo.*;
import com.kedacom.ctsp.web.controller.message.ResponseMessage;
import com.kedacom.ctsp.web.entity.page.PagerResult;
import com.kedacom.ctsp.web.entity.param.QueryParamEntity;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * oauth2 资源服务
 *
 * @author xuwei
 * @create 2018-05-16 20:08
 **/
@FeignClient(name = "resource", url = "${commons.oauth2.client.serverInUri}")
public interface OAuth2ResourceService {
    /**
     * 通过accessToken获取登录信息
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/getLoginUser")
    ResponseMessage<OAuth2Authentication> getUserByAccessToken(@RequestBody UserQueryParam param);

    /**
     * 通过jwt获取登录信息
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/getLoginUserByJwt")
    ResponseMessage<OAuth2Authentication> getLoginUserByJwt(@RequestBody JwtQueryParam param);

    /**
     * 获取用户信息
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/user")
    ResponseMessage<PagerResult<PlainUser>> queryUser(@RequestBody ClientQueryParam param);

    /**
     * 获取部门列表
     * 如果pid不为空, 查找指定父级下的所有子节点
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/dept")
    ResponseMessage<PagerResult<PlainDepartment>> queryDept(@RequestParam(value = "pid") String pid, @RequestBody ClientQueryParam param);

    /**
     * 通过指定用户获取部门列表
     * 如果pid不为空, 查找指定父级下的所有子节点
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/dept_by_user")
    ResponseMessage<PagerResult<PlainDepartment>> queryDept(@RequestParam(value = "pid", required = false) String pid, @RequestBody UserQueryParam param);


    /**
     * 获取部门数
     * 如果pid不为空, 查找指定父级下的所有子节点
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/dept/tree")
    ResponseMessage<List<DepartmentVO>> queryDeptAsTree(@RequestParam(value = "pid", required = false) String pid, @RequestBody ClientQueryParam param);

    /**
     * 通过指定用户获取部门树
     * 如果pid不为空, 查找指定父级下的所有子节点
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/dept_by_user/tree")
    ResponseMessage<List<DepartmentVO>> queryDeptAsTree(@RequestParam(value = "pid", required = false) String pid, @RequestBody UserQueryParam param);

    /**
     * 获取人员信息
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/person")
    ResponseMessage<PagerResult<PlainPerson>> queryPerson(@RequestBody ClientQueryParam param);

    /**
     * 获取角色信息
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/role")
    ResponseMessage<PagerResult<PlainRole>> queryRole(@RequestBody ClientQueryParam param);

    /**
     * 通过用户获取资源信息
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/role_by_user")
    ResponseMessage<PagerResult<PlainRole>> queryRoleByUser(@RequestBody UserQueryParam param);


    /**
     * 获取资源信息
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/permission")
    ResponseMessage<PagerResult<PlainResource>> queryResource(@RequestParam(value = "pid", required = false) String pid, @RequestBody ClientQueryParam param);

    /**
     * 通过用户获取资源信息
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/permission_by_user")
    ResponseMessage<PagerResult<PlainResource>> queryResourceByUser(@RequestParam(value = "pid", required = false) String pid, @RequestBody UserQueryParam param);

    /**
     * 获取资源信息
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/permission/tree")
    ResponseMessage<List<ResourceVO>> queryResourceAsTree(@RequestParam(value = "pid", required = false) String pid, @RequestBody ClientQueryParam param);

    /**
     * 通过用户获取资源信息
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/permission_by_user/tree")
    ResponseMessage<List<ResourceVO>> queryResourceAsTreeByUser(@RequestParam(value = "pid", required = false) String pid, @RequestBody UserQueryParam param);

    /**
     * 修改密码
     *
     * @param map
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT, value = "/resources/password")
    ResponseMessage<Object> updatePassword(@RequestBody Map map);

    /**
     * 调用客户端client信息
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/client/list")
    ResponseMessage<PagerResult<PlainClient>> clientList(@RequestBody QueryParamEntity param);

    /**
     * 通过用户获取绑定项目
     *
     * @param param
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/client/userClient")
    ResponseMessage<List<PlainClient>> getUserClient(@RequestBody UserQueryParam param);


    /**
     * 根据accessToken获取权限资源信息
     *
     * @param authentication
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/loadResources")
    ResponseMessage<List<AuthResource>> loadResources(@RequestBody AuthResourceQueryParam authentication);

    /**
     * 根据accessToken获取资源信息
     *
     * @param authentication
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/resources/authResource")
    ResponseMessage<Set<AuthResource>> getAuthResource(@RequestBody OAuth2Authentication authentication);
}
